package blackitheima2.ThreadPool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {
    public static void main(String[] args) {
        ThreadPoolExecutor executor=new ThreadPoolExecutor(
                //核心线程的最大值
                1,
                //最大线程
                2,
                //空闲线程最大存活时间
                0L,
                //时间单位
                TimeUnit.MICROSECONDS,
                //任务队列
                new ArrayBlockingQueue<>(3),
                //创建线程工厂
                Executors.defaultThreadFactory(),
                //任务的拒绝策略
                new ThreadPoolExecutor.AbortPolicy()
        );
        executor.execute(new MyRunnable("任务1"));//线程1
        executor.execute(new MyRunnable("任务2"));//线程1
        executor.execute(new MyRunnable("任务3"));//线程1
        executor.execute(new MyRunnable("任务4"));//线程1
        executor.execute(new MyRunnable("任务5"));//线程2,新创建的线程
        executor.execute(new MyRunnable("任务6"));//任务拒绝
        executor.shutdown();
    }
}
